class World:
    def __init__(self):
        self.entities = []
        self.systems = []
        self.events = []
        self.next_entity_id = 1
        self._system_map = {}  # 系统名称到实例的映射

    def add_entity(self, entity):
        entity.id = self.next_entity_id
        self.next_entity_id += 1
        self.entities.append(entity)
        return entity

    def add_system(self, system):
        system.world = self
        self.systems.append(system)
        # 存储系统类型到实例的映射
        self._system_map[type(system).__name__] = system

    def get_system(self, system_name):
        """根据系统名称获取系统实例"""
        return self._system_map.get(system_name)
        
    def update(self, dt):
        """更新所有系统"""
        for system in self.systems:
            system.update(self.entities, dt)